require('../../assets/css/index.less')
require('./font_385/iconfont.css');
require('./home.less')
require('../../assets/css/basic.less')
let renderTabbar= require('../../xios/tabe')
// console.log(renderTabbar);
// 引用swiper的css
 require('swiper')
// 引入swiper
const mySwiper = require('swiper/dist/css/swiper.min.css');
// 引入axios
 let request= require('../../xios/axios')
window.onload = () => {
    renderTabbar('mine');
    // 获取元素  
  let rankNo=document.querySelector('.rankNo')
  let clockDay= document.querySelector('.clockDay')
  let clock= document.querySelector('.p22')
  let badge= document.querySelector('.badge')
  console.log(clock);
//   clock.addEventListener('click',function(){
//     console.log(clock);
//   })
    // 使用swiper
    let mySwiper = new Swiper('.swiper-container', {
        autoplay: 1000,//可选选项，自动滑动
        initialSlide: 0,
        pagination: '.swiper-pagination',
        loop: true,
    })

  request.get('/api/user/clockInInfo').then(res=>{
     console.log(res.data);  
  })
 //获取打卡信息
  function getclockinfo(){
    request.get('/api/user/clockInInfo').then(res=>{
        console.log(res.data);
                // 解构数据
      let  {erron,data}= res.data
      //   2.判断
    
         if(data.isClockIn){
          clock.textContent='今日已打卡'
          clock.className='p33'
         }else{
            clock.textContent='今日打卡'
            clock.className='clock'
         }
    })
  }
  getclockinfo()
//获取用户信息
function getuserinfo(){
    request.get('/api/user/info').then(res=>{
        // 解构数据
      let  {erron,data}= res.data
    //   2.判断
    render(data)
    })
  
}
//渲染
function render(data){
    rankNo.textContent=data.ranking
    clockDay.textContent=data.clockCount
    badge.textContent=data.badges
}

getuserinfo();
clock.addEventListener('click',function(){
    console.log(1);
    request.post('/api/user/clockIn').then(res=>{
        let  {erron,message}= res.data
        if(erron===0){
            request.post('/api/user/clockInInfo').then(res=>{
                let  {erron,data}= res.data
                if(erron===0){
                    clock.textContent='已打卡'
                    render(data)
                }
            })
            console.log(2);
        }else{
            alert(message)
        }
    })

})
}